package practise.sort.javaSort;

import practise.sort.Person;

import java.util.ArrayList;
import java.util.Collections;
import java.util.List;

/**
 * Created by richard on 5/6/14.
 */
public class Javasort {
    public static void main(String[] args){
        Javasort javasort = new Javasort();
        List<ComparablePerson> persons = javasort.initPerson();
        Collections.sort(persons);
        javasort.print(persons);

        List<ComparablePerson> persons2 = javasort.initPerson();
        Collections.sort(persons2,new PersonComparator());
        javasort.print(persons);
    }

    public void print(List<ComparablePerson> list){
        for(Person peson : list){
            System.out.println("age:"+peson.getAge()+"name:"+peson.getName());
        }
    }

    public List<ComparablePerson> initPerson(){
        List<ComparablePerson> persons = new ArrayList<ComparablePerson>();
        persons.add(new ComparablePerson(1,"1"));
        persons.add(new ComparablePerson(5,"6"));
        persons.add(new ComparablePerson(5,"5"));
        persons.add(new ComparablePerson(2,"2"));
        return persons;
    }
}
